<?php
include_once ('model/Student/class-student.php');
include_once ('model/Staff/class-course.php');
include_once ('model/Staff/class-trainningitem.php');
include_once( "model/Staff/class-registerable-course.php");
include_once ('control/student-proc.php');
include_once ('model/currentSemester.php');
session_start();

$student;
if(!isset($_SESSION["user"])){
    header("location:http:/educational/index.php");
} else {
	$student = $_SESSION["user"];
	include_once ('model/connect.php');
}
?>
<!DOCTYPE html>
<html xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Educational</title>
<?php include("header-srcipt.php");?>
</head>
<body>
<div class="wrapper col0">
  <div id="topbar">
  	<div id="loginpanel">
      <ul>
        <li class="left">Welcome <?php echo($student->getStudentName());?> </li>
      </ul>
    </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<?php include("header-title.php");?>
<!-- ####################################################################################################### -->
<?php include("student-menu-main.php");?>
<!-- ####################################################################################################### -->
<div class="wrapper col4">
  <div id="container">
  <?php if($resigerMode) {  
  	$programID = lookupTrainProgramID($student->getStudentClassID());
	$trainItem = new TrainningItem;
	$studentSemester = calStudentSemester($currentSemester,$currentYear,calStudentYear($student->getStudentClassID())) + 1;
	
	$registeredCourse = $student->getCourseRegistrationID();
  ?>
  <form method="get" action="#" style="padding:10px;">
  	Lọc&nbsp;
    <select name="mode">
  <?php
  	
	
	$templist;
	if(isset($_GET["mode"])) {
		switch ($_GET["mode"]) {
			case "lop":
				$templist = $trainItem->listTrnpItemInProgram($programID,$studentSemester,$registeredCourse);
				renderOpptionTag("all",lookupTrainProgramName($programID),false);
				renderOpptionTag("lop",lookupClassName($student->getStudentClassID()),true);		
				break;
			case "all":	
				$templist = $trainItem->listTrnpItemInProgramAll($programID,$registeredCourse);
				renderOpptionTag("all",lookupTrainProgramName($programID),true);
				renderOpptionTag("lop",lookupClassName($student->getStudentClassID()),false);
				break;
		}
	} else {
		$templist = $trainItem->listTrnpItemInProgram($programID,$studentSemester,$registeredCourse);
		renderOpptionTag("all",lookupTrainProgramName($programID),false);
		renderOpptionTag("lop",lookupClassName($student->getStudentClassID()),true);	
	}
   ?>  
    </select>&nbsp;
    <input type="submit" value="Go" />
  </form>
  </form>
  <form  method="post" action="control/student-register-course.php">
  	<input type="hidden" value="<?php echo $student->getStudentId();?>" name="studentid" />
  <table>
  	<thead>
     <tr>
    	<th>Mã môn</th>
        <th>Tên môn</th>
        <th>Số tính chỉ</th>
        <th>Học kỳ gợi ý</th>
        <th>Chương trình học</th>
        <th>Đăng ký</th>
        
      </tr>  
    </thead>
    <?php 
		foreach($templist as $regCourse) {
			$status = $student->checkCourseAvailability($regCourse->getCourseId());
	 ?>
    <tr>
    	<td><?php echo($regCourse->getCourseId());?></td>
        <td><?php echo($regCourse->getCourseName());?></td>
        <td><?php echo($regCourse->getCourseCredit());?></td>
        <td><?php echo($regCourse->getSemester());?></td>
        <td><?php echo($regCourse->getSyllabus());?></td>
        <td align="center" width="300px">
        	<?php if ($status == 0) {?>
                    <input type="checkbox" value="<?php echo $regCourse->getCourseId();?>" name="courseid[]" />
            <?php } else if ($status < 0) {?>
                Cần có môn "<?php echo(lookupCoursename($status*-1));?>"trước đó.
            <?php } else {?>
            	Học cùng với môn "<?php echo(lookupCoursename($status));?>"</button><br/>
            <?php }?>
        </td>
    </tr>
    <?php } ?>
  </table>
  <input type="submit" value="Đăng ký" style="float:right"/><div class="clear"></div>
  </form>
  <?php } else { ?>
  <table><tr><td align="center"><h1>Hệ thống đăng ký môn học chưa được mở</h1></td></tr></table>	
  <?php }?>
  </div>
</div>
<!-- ####################################################################################################### -->
<?php include("footer.php");?>
</body>
</html>
